/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package aviso.util;

/**
 *
 * @author avgusti
 */
public class CssUtil {

    public static String resH(int h) {
        String base = "000000";
        String hs = Integer.toHexString(h);
        int l = hs.length();
        if (l < 6) {
            hs = base.substring(0, 6 - l) + hs;
        }
        return "#" + hs;
    }

    public static String resAsRGBA(int h) //opactiy is in last byte
    {
        String a = Float.toString((h & 0x000000ff) / 255.0f);
        if (a.length() > 5) {
            a = a.substring(0, 4);
        }
        String b = Integer.toString((h & 0x0000ff00) >>> 8);
        String g = Integer.toString((h & 0x00ff0000) >>> 16);
        String r = Integer.toString((h & 0xff000000) >>> 24);
        return "rgba(" + r + "," + g + "," + b + "," + a + ")";
    }

    public static String resAsRGBA(int h, double a) {

        String b = Integer.toString((h & 0x0000ff));
        String g = Integer.toString((h & 0x00ff00) >>> 8);
        String r = Integer.toString((h & 0xff0000) >>> 16);
        return "rgba(" + r + "," + g + "," + b + "," + a + ")";
    }

    public static String resAsRGBA(int r, int g, int b, float a) {
        return "rgba(" + r + "," + g + "," + b + "," + a + ")";
    }

    public static String resAsRGB(int r, int g, int b) {
        return "rgb(" + r + "," + g + "," + b + ")";
    }

    public static String resAsRGB(int h) {
        String b = Integer.toString((h & 0x0000ff));
        String g = Integer.toString((h & 0x00ff00) >>> 8);
        String r = Integer.toString((h & 0xff0000) >>> 16);
        return "rgb(" + r + "," + g + "," + b + ")";
    }
}
